package com.briup.web;

import com.briup.pojo.Customer;
import com.briup.pojo.Shopcar;
import com.briup.service.IShopCarService;
import com.briup.serviceImp.ShopCarServiceImp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


public class ShopCarServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Customer customer = (Customer) request.getSession().getAttribute("login");
        if (customer ==null){
            request.getRequestDispatcher("/login.jsp").forward(request,response);
        }
        IShopCarService shopCarServiceImp = new ShopCarServiceImp();
        List<Shopcar> shopcars = shopCarServiceImp.findByCustomer(customer);
        request.getSession().setAttribute("shopcar",shopcars);
        for (Shopcar s : shopcars ) {
      System.out.println(s);
        }
        request.getRequestDispatcher("/user/shopCart.jsp").forward(request,response);
    }
}
